<?php
if(Yii::app()->controller->action->id != 'create')
{
    ?>
    <li class="box-btnAddItem <?php echo empty($model->itens[0]['TIPO_ID'])? '':'hide';?>">
        <section class="input-append">
            <?php echo CHtml::textField('addItens','',array('placeholder'=>'Clique para Adicionar','onkeypress'=>"enterKey(e);"));?>
            <button type="button" class="btn" onclick='addItem();' id="btnAdd" >Adicionar</button>
            <button type="button" class="btn" onclick='addItemText();' id="addOutros" >Texto</button>
        </section>
    </li>
        <?php
    if(empty($model->itens[0]['TIPO_ID']))
    {

        foreach ($model->itens as $item)
        {
            if(empty($item['TIPO_ID']) )
            {
                ?>
                <input type="hidden" value="<?php echo $item['ID'];?>"  name="Item[UPDATE][<?php echo $item['ID'];?>][ID]"/>
                <section class="update-itens">
                    <li>
                        <section class="input-append input-prepend">
                            <span class="add-on"><i class="icon-search"></i></span>
                            <input type="text" value="<?php echo $item['TITULO'];?>"  name="Item[UPDATE][<?php echo $item['ID'];?>][TITULO]"/>
                            <button class="btn" onclick="$(this).parent().remove();">&times;</button>
                        </section>
                    </li>
                </section>
            <?php
            }else{
                ?>
                <input type="hidden" value="<?php echo $item['ID'];?>"  name="Item[UPDATE][<?php echo $item['ID'];?>][ID]"/>
                <section class="update-item-text">
                    <li id="type-text">
                        <section class="input-append input-prepend">
                            <span class="add-on"><i class="icon-text-height"></i></span>
                            <input type="text" value="<?php echo $item['TITULO'];?>" data-type='text' id='text' name="Item[UPDATE][<?php echo $item['ID'];?>][TEXT]"/>
                            <a href="javascript:;" class="btn" onclick="$(this).parent().remove();$('#addOutros').show();">&times;</a>
                        </section>
                    </li>
                </section>
            <?php
            }
        }
        ?>

    <?php
    }else{
        ?>
        <input type="hidden" value="<?php echo $model->itens[0]['ID'];?>"  id="item-text-Id" name="Item[UPDATE][<?php echo $model->itens[0]['ID'];?>][ID]"/>
        <section class="update-lista-itens-text">
            <li>
                <section class="">
                    <textarea cols="10" rows="1" name="Item[UPDATE][<?php echo $model->itens[0]['ID'];?>][TEXT]" id="text" readonly="readonly" placeholder="Texto de exemplo..." style="resize: none;"></textarea>
                </section>
            </li>
        </section>
    <?php
    }
}
else

{
    ?>
    <li class="box-btnAddItem <?php echo !empty($model->itens)? '':'hide';?>">
        <section class="input-append">
        <?php echo CHtml::textField('addItens','',array('placeholder'=>'Clique para Adicionar','onkeypress'=>"enterKey(e);"));?>
            <button type="button" class="btn" onclick='addItem();' id="btnAdd" >Adicionar</button>
            <button type="button" class="btn" onclick='addItemText();' id="addOutros" >Texto</button>
        </section>
    </li>
<?php
}
?>
<section id="box-lista-itens"></section>
<section id="box-lista-itens-text"></section>